package research.core;

import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarContributionItem;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ContributionItemFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

public class ApplicationActionBarAdvisor extends ActionBarAdvisor {

    private IWorkbenchAction exitAction;
    private IWorkbenchAction aboutAction;
    private IWorkbenchAction newWindowAction;
    private IWorkbenchAction saveAction;
    private IWorkbenchAction closeAction;
    private IWorkbenchAction closeAllAction;
    private IWorkbenchAction preferencesAction;
	private IWorkbenchAction saveAllAction;
	private IContributionItem viewsMenu;
	private IContributionItem perspectivesMenu;
	private IWorkbenchAction resetAction;
    

    public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
        super(configurer);
    }
    
    protected void makeActions(final IWorkbenchWindow window) {
        exitAction = ActionFactory.QUIT.create(window);
        exitAction.setText("Выход");
        register(exitAction);
        
        aboutAction = ActionFactory.ABOUT.create(window);
        aboutAction.setText("О программе");
        register(aboutAction);
        
        newWindowAction = ActionFactory.OPEN_NEW_WINDOW.create(window);
        newWindowAction.setText("Новое окно");
        register(newWindowAction);
        
        saveAction = ActionFactory.SAVE.create(window);
        saveAction.setText("Сохранить");
        register(saveAction);
        
        closeAction = ActionFactory.CLOSE.create(window);
        closeAction.setText("Закрыть");
        register(closeAction);
        
        closeAllAction = ActionFactory.CLOSE_ALL.create(window);
        closeAllAction.setText("Закрыть все");
        register(closeAllAction);
        
        preferencesAction = ActionFactory.PREFERENCES.create(window);
        preferencesAction.setText("Настройки");
        register(preferencesAction);
        
        saveAllAction = ActionFactory.SAVE_ALL.create(window);
        saveAllAction.setText("Сохранить все");
        register(saveAllAction);
        
        resetAction = ActionFactory.RESET_PERSPECTIVE.create(window);
        resetAction.setText("Восстановить перспективу");
        register(resetAction);
        
        viewsMenu = ContributionItemFactory.VIEWS_SHORTLIST.create(window);
        
        perspectivesMenu = ContributionItemFactory.PERSPECTIVES_SHORTLIST.create(window);
    }
    
    protected void fillMenuBar(IMenuManager menuBar) {
        MenuManager fileMenu = new MenuManager("&Файл", IWorkbenchActionConstants.M_FILE);
        MenuManager windowMenu = new MenuManager("&Окно", IWorkbenchActionConstants.M_WINDOW);
        MenuManager helpMenu = new MenuManager("&Справка", IWorkbenchActionConstants.M_HELP);
        menuBar.add(fileMenu);
        menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
        menuBar.add(windowMenu);
        menuBar.add(helpMenu);
        
        // File
        fileMenu.add(newWindowAction);
        fileMenu.add(new Separator());
        fileMenu.add(saveAction);
        fileMenu.add(saveAllAction);
        fileMenu.add(new Separator());
        fileMenu.add(closeAction);
        fileMenu.add(closeAllAction);
        fileMenu.add(new Separator());
        fileMenu.add(preferencesAction);
        fileMenu.add(new Separator());
        fileMenu.add(exitAction);
        
        // Window
		MenuManager views = new MenuManager("Вид", "views");
		views.add(viewsMenu);
		windowMenu.add(views);
		MenuManager perspectives = new MenuManager("Перспектива", "perspectives");
		perspectives.add(perspectivesMenu);
		windowMenu.add(perspectives);
		windowMenu.add(new Separator());
		windowMenu.add(resetAction);
        
        // Help
        helpMenu.add(aboutAction);
    }
    
    protected void fillCoolBar(ICoolBarManager coolBar) {
        IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
        
        toolbar.add(saveAction);
        toolbar.add(saveAllAction);
        
        coolBar.add(new ToolBarContributionItem(toolbar, "main"));   
    }
}
